<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
    <link rel="stylesheet" href="../assets/app/css/app.css" />
    <script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/jquery.form.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
</head>
<body>
<!--通用顶部-->
<!--通用顶部结束-->

<section>
<div class="content login-content" style="margin-top:10px;">
    <div class="input-group" id="login-form">
        <input type="text" placeholder="请输入手机号/邮箱" name="account" class="user-user" id="txtAccount">
        <input type="password" placeholder="请输入用户密码" name="password" class="user-pwd" id="txtPassword">
      <button class="btn btn-positive btn-block login-btn" id="btnLogin">登录</button>
      <div class="login-bottom">       
      <a href="javascript:randomSwitchBtn('findpwd',api);">忘记密码？</a>
      </div>
    </div>
    <div class="clear"></div>
    <button class="btn btn-negative btn-block btn-outlined reg-btn" onclick="javascript:randomSwitchBtn('register',api);">通过手机号注册</button>

       <div class="block50"></div>
       <div class="block30"></div>
       <p style="text-align:center;"><a href="javascript:;" id="private">隐私政策</a>｜<a href="javascript:;" id="newso">服务协议</a></p>
      <p style="text-align:center;">版权所有© Copyright 2016</p>
      <div class="block20"></div>

</div>
                
</section>

</body>

<script type="text/javascript">

apiready = function(){
   	var header = $api.byId('header');
   	
   	
   	var _private = document.getElementById('private');
   	var newso = document.getElementById('newso');
   	_private.onclick = function(){
   		api.openWin({name:'private',url:'./private.html',reload:true});
   	};
   	newso.onclick = function(){
   		api.openWin({name:'newso',url:'./newso.html',reload:true});
   	};
   	
   	
   	if(getUserinfo()){
   		api.closeWin();
   	}
   	
};
function clearInput(){
    document.getElementById('txtAccount').value='';
    document.getElementById('txtPassword').value='';
}
if(!getUserinfo()){
	var btnLogin = document.getElementById('btnLogin');
	btnLogin.onclick = function(){
	    var username = document.getElementById('txtAccount').value;
	    var password = document.getElementById('txtPassword').value;
	    var pwd = base64encode(utf16to8(password));
	    api.showProgress({title : '正在登录...',text : ''});
	    $.ajax({
	        type : 'post',
	        url:config.url+'/app.php?act=appuserlogin',
	        dataType:'jsonp',
	        data : {
	           'username' : username,
	           'password' : pwd
	        },
			success : function(ret,err){
			api.hideProgress();
	       if(ret['state'] == 0){
	    	   localData.set('user_is_login','yes');
	           var userinfo = {
	                   'uid' : ret['uid'],
	                   'email' : ret['email'],
	                   'mobile' : ret['mobile'],
	                   'username' : ret['username'],
	                   'qianming' : ret['qianming'],
					   'isAgent' : ret['type_agent'],
	                   'face' : ret['thumb'],
	                   'ushell' : ret['ushell']
	               };
	            localData.set('userinfo',JSON.stringify(userinfo));
	            appToast('登录成功');
	            //alert(ret['state']);
	            //randomSwitchBtn('user'); //跳转个人中心
				//window.location.href = './user.html';
	            setTimeout(function(){
	            	appClose('setpwd',api);
	            	appClose('findmobilecheck',api);
	            	appClose('findpwd',api);
	            	appClose('findsetpwd',api);
	            	appClose('basedata',api);
					var reloadPage = localData.get('reload');
					localData.remove('reload');
					if(reloadPage == 'applyfor'){
						var jsfun = 'funcGoto();';
						api.execScript({
						    name: 'applyfor',
						    frameName: 'registerFram',
						    script: jsfun
						});
					}else if(reloadPage == 'user'){
		            	var jsfun = 'funcGotoUser();';
		                api.execScript({
		                    name: 'root',
		                    script: jsfun
		                });
					}else if(reloadPage == 'userrecharge'){
						var jsfun = 'funcGoto();';
						api.execScript({
						    name: 'userrecharge',
						    frameName: 'userrechargeFram',
						    script: jsfun
						});
					}
	            	appClose('login',api);
	            },150);
				clearInput();
	       }
	       if(ret['state'] == 1 && ret['num'] == -2){
	            appToast('帐号不存在或密码错误');
	
	       }
	       if(ret['state'] == 2){
	            appToast('帐号未认证，跳转认证');
	          
	       }
	        if(ret['state'] == 1 && ret['num'] == -1){
	            appToast('帐号或密码错误');
	           
	        }
	    }

	    });
	}
}
</script>
</html>